package net.yxsoft.service;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import net.yxsoft.kit.FlashcatKit;
import net.yxsoft.service.common.BaseService;
import org.apache.commons.lang.StringUtils;

import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

public class MachineMonitorService extends BaseService {
    public static final MachineMonitorService INSTANCE = new MachineMonitorService();
    /**
     * 查看cpu使用率
     *  ident 机器标识
     *  date  日期
     *  contrastDate 比对日期
     *  startHour  开始时间（小时）
     *  endHour   结束时间（小时）
     *  step   时间颗粒度
     *  datasoureId 数据源id
     *  authorization  认证字符串
     * */
    public JsonNode cpuUsageSystem(String ident,String date,String contrastDate,String startHour,String endHour,String step,String datasoureId,String authorization){
        try{
            if(StringUtils.isBlank(startHour)){
                LocalTime oneHourAgoTime = LocalTime.now().minusHours(2);
                startHour = oneHourAgoTime.format(DateTimeFormatter.ofPattern("HH:mm:ss"));
            }
            if(StringUtils.isBlank(endHour)){
                endHour = LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss"));
            }
            Long start =null;
            Long end =null;
            if(StringUtils.isBlank(date)){
                end = FlashcatKit.getNowTime(null);
                start= FlashcatKit.getNowTime((long) (30 * 60 * 1000));
            }else {
                start = FlashcatKit.formatTime(date+" "+startHour);
                end = FlashcatKit.formatTime(date+" "+endHour);
            }
            Long contrastStart =null;
            Long contrastEnd =null;
            if(StringUtils.isNotBlank(contrastDate)){
                contrastStart = FlashcatKit.formatTime(contrastDate+" "+startHour);
                contrastEnd = FlashcatKit.formatTime(contrastDate+" "+endHour);
            }
            JsonNode jsonNode = FlashcatKit.cpuUsageSystem(ident, start, end, contrastStart, contrastEnd, step, datasoureId, authorization);
            return  jsonNode;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 查看内存使用率
     *  ident 机器标识
     *  date  日期
     *  contrastDate 比对日期
     *  startHour  开始时间（小时）
     *  endHour   结束时间（小时）
     *  step   时间颗粒度
     *  datasoureId 数据源id
     *  authorization  认证字符串
     * */
    public JsonNode memUsedPercent(String ident,String date,String contrastDate,String startHour,String endHour,String step,String datasoureId,String authorization){
        try{
            if(StringUtils.isBlank(startHour)){
                LocalTime oneHourAgoTime = LocalTime.now().minusHours(2);
                startHour = oneHourAgoTime.format(DateTimeFormatter.ofPattern("HH:mm:ss"));
            }
            if(StringUtils.isBlank(endHour)){
                endHour = LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss"));
            }
            Long start =null;
            Long end =null;
            if(StringUtils.isBlank(date)){
                end = FlashcatKit.getNowTime(null);
                start= FlashcatKit.getNowTime((long) (30 * 60 * 1000));
            }else {
                start = FlashcatKit.formatTime(date+" "+startHour);
                end = FlashcatKit.formatTime(date+" "+endHour);
            }
            Long contrastStart =null;
            Long contrastEnd =null;
            if(StringUtils.isNotBlank(contrastDate)){
                contrastStart = FlashcatKit.formatTime(contrastDate+" "+startHour);
                contrastEnd = FlashcatKit.formatTime(contrastDate+" "+endHour);
            }
            JsonNode jsonNode = FlashcatKit.memUsedPercent(ident, start, end, contrastStart, contrastEnd, step, datasoureId, authorization);
            return  jsonNode;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 查看硬盘使用率
     *  ident 机器标识
     *  date  日期
     *  contrastDate 比对日期
     *  startHour  开始时间（小时）
     *  endHour   结束时间（小时）
     *  step   时间颗粒度
     *  datasoureId 数据源id
     *  authorization  认证字符串
     * */
    public JsonNode diskUsedPercent(String ident,String date,String contrastDate,String startHour,String endHour,String step,String datasoureId,String authorization){
        try{
            if(StringUtils.isBlank(startHour)){
                LocalTime oneHourAgoTime = LocalTime.now().minusHours(2);
                startHour = oneHourAgoTime.format(DateTimeFormatter.ofPattern("HH:mm:ss"));
            }
            if(StringUtils.isBlank(endHour)){
                endHour = LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss"));
            }
            Long start =null;
            Long end =null;
            if(StringUtils.isBlank(date)){
                end = FlashcatKit.getNowTime(null);
                start= FlashcatKit.getNowTime((long) (30 * 60 * 1000));
            }else {
                start = FlashcatKit.formatTime(date+" "+startHour);
                end = FlashcatKit.formatTime(date+" "+endHour);
            }
            Long contrastStart =null;
            Long contrastEnd =null;
            if(StringUtils.isNotBlank(contrastDate)){
                contrastStart = FlashcatKit.formatTime(contrastDate+" "+startHour);
                contrastEnd = FlashcatKit.formatTime(contrastDate+" "+endHour);
            }
            JsonNode jsonNode = FlashcatKit.diskUsedPercent(ident, start, end, contrastStart, contrastEnd, step, datasoureId, authorization);
            return  jsonNode;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 查看上行带宽
     *  ident 机器标识
     *  date  日期
     *  contrastDate 比对日期
     *  startHour  开始时间（小时）
     *  endHour   结束时间（小时）
     *  step   时间颗粒度
     *  datasoureId 数据源id
     *  authorization  认证字符串
     * */
    public JsonNode netBytesSent(String ident,String date,String contrastDate,String startHour,String endHour,String step,String datasoureId,String authorization){
        try{
            if(StringUtils.isBlank(startHour)){
                LocalTime oneHourAgoTime = LocalTime.now().minusHours(2);
                startHour = oneHourAgoTime.format(DateTimeFormatter.ofPattern("HH:mm:ss"));
            }
            if(StringUtils.isBlank(endHour)){
                endHour = LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss"));
            }
            Long start =null;
            Long end =null;
            if(StringUtils.isBlank(date)){
                end = FlashcatKit.getNowTime(null);
                start= FlashcatKit.getNowTime((long) (30 * 60 * 1000));
            }else {
                start = FlashcatKit.formatTime(date+" "+startHour);
                end = FlashcatKit.formatTime(date+" "+endHour);
            }
            Long contrastStart =null;
            Long contrastEnd =null;
            if(StringUtils.isNotBlank(contrastDate)){
                contrastStart = FlashcatKit.formatTime(contrastDate+" "+startHour);
                contrastEnd = FlashcatKit.formatTime(contrastDate+" "+endHour);
            }
            JsonNode jsonNode = FlashcatKit.netBytesSent(ident, start, end, contrastStart, contrastEnd, step, datasoureId, authorization);
            return  jsonNode;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }


    /**
     *  区块链高度
     * chainId 链ID
     * job  链节点
     *  date  日期
     * contrastDate 比对日期
     * startHour  开始时间（小时）
     * endHour   结束时间（小时）
     * step   时间颗粒度
     *  datasoureId 数据源id
     * authorization  认证字符串
     */
    public ArrayNode chainmakerBlockCounter(String chainId, String job, String date, String contrastDate, String startHour, String endHour, String step,String datasoureId, String authorization){
        try{
            if(StringUtils.isBlank(startHour)){
                LocalTime oneHourAgoTime = LocalTime.now().minusHours(2);
                startHour = oneHourAgoTime.format(DateTimeFormatter.ofPattern("HH:mm:ss"));
            }
            if(StringUtils.isBlank(endHour)){
                endHour = LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss"));
            }
            Long start =null;
            Long end =null;
            if(StringUtils.isBlank(date)){
                end = FlashcatKit.getNowTime(null);
                start= FlashcatKit.getNowTime((long) (30 * 60 * 1000));
            }else {
                start = FlashcatKit.formatTime(date+" "+startHour);
                end = FlashcatKit.formatTime(date+" "+endHour);
            }
            Long contrastStart =null;
            Long contrastEnd =null;
            if(StringUtils.isNotBlank(contrastDate)){
                contrastStart = FlashcatKit.formatTime(contrastDate+" "+startHour);
                contrastEnd = FlashcatKit.formatTime(contrastDate+" "+endHour);
            }
            ObjectMapper mapper = new ObjectMapper();
            // 创建一个ArrayNode对象
            ArrayNode jsonArray = mapper.createArrayNode();
            JsonNode chainmakerAvgTps = FlashcatKit.chainmakerBlockCounter(chainId, job, start, end, step,datasoureId, authorization);
            if(chainmakerAvgTps!=null&&"success".equals(chainmakerAvgTps.get("status").asText())){
                jsonArray.add(chainmakerAvgTps.get("data").get("result"));
            }else {
                jsonArray.addArray();
            }
            JsonNode chainmakerAvgTps2 = FlashcatKit.chainmakerBlockCounter(chainId, job, contrastStart, contrastEnd, step,datasoureId, authorization);
            if(chainmakerAvgTps2!=null&&"success".equals(chainmakerAvgTps2.get("status").asText())){
                jsonArray.add(chainmakerAvgTps2.get("data").get("result"));
            }else {
                jsonArray.addArray();
            }
            return  jsonArray;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }


    /**
     *  交易池数量
     * chainId 链ID
     * job  链节点
     *  date  日期
     * contrastDate 比对日期
     * startHour  开始时间（小时）
     * endHour   结束时间（小时）
     * step   时间颗粒度
     *  datasoureId 数据源id
     * authorization  认证字符串
     */
    public ArrayNode chainmakerTxPoolSize(String chainId, String job, String date, String contrastDate, String startHour, String endHour, String step,String datasoureId, String authorization){
        try{
            if(StringUtils.isBlank(startHour)){
                LocalTime oneHourAgoTime = LocalTime.now().minusHours(2);
                startHour = oneHourAgoTime.format(DateTimeFormatter.ofPattern("HH:mm:ss"));
            }
            if(StringUtils.isBlank(endHour)){
                endHour = LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss"));
            }
            Long start =null;
            Long end =null;
            if(StringUtils.isBlank(date)){
                end = FlashcatKit.getNowTime(null);
                start= FlashcatKit.getNowTime((long) (30 * 60 * 1000));
            }else {
                start = FlashcatKit.formatTime(date+" "+startHour);
                end = FlashcatKit.formatTime(date+" "+endHour);
            }
            Long contrastStart =null;
            Long contrastEnd =null;
            if(StringUtils.isNotBlank(contrastDate)){
                contrastStart = FlashcatKit.formatTime(contrastDate+" "+startHour);
                contrastEnd = FlashcatKit.formatTime(contrastDate+" "+endHour);
            }
            ObjectMapper mapper = new ObjectMapper();
            // 创建一个ArrayNode对象
            ArrayNode jsonArray = mapper.createArrayNode();
            JsonNode chainmakerAvgTps = FlashcatKit.chainmakerTxPoolSize(chainId, job, start, end, step,datasoureId, authorization);
            if(chainmakerAvgTps!=null&&"success".equals(chainmakerAvgTps.get("status").asText())){
                jsonArray.add(chainmakerAvgTps.get("data").get("result"));
            }else {
                jsonArray.addArray();
            }
            JsonNode chainmakerAvgTps2 = FlashcatKit.chainmakerTxPoolSize(chainId, job, contrastStart, contrastEnd, step,datasoureId, authorization);
            if(chainmakerAvgTps2!=null&&"success".equals(chainmakerAvgTps2.get("status").asText())){
                jsonArray.add(chainmakerAvgTps2.get("data").get("result"));
            }else {
                jsonArray.addArray();
            }
            return  jsonArray;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }


    /**
     * 区块链tps
     * chainId 链ID
     * job  链节点
     *  date  日期
     * contrastDate 比对日期
     * startHour  开始时间（小时）
     * endHour   结束时间（小时）
     * step   时间颗粒度
     *  datasoureId 数据源id
     * authorization  认证字符串
     */
    public ArrayNode chainmakerTps(String chainId, String job, String date, String contrastDate, String startHour, String endHour, String step,String datasoureId, String authorization){
        try{
            if(StringUtils.isBlank(startHour)){
                LocalTime oneHourAgoTime = LocalTime.now().minusHours(2);
                startHour = oneHourAgoTime.format(DateTimeFormatter.ofPattern("HH:mm:ss"));
            }
            if(StringUtils.isBlank(endHour)){
                endHour = LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss"));
            }
            Long start =null;
            Long end =null;
            if(StringUtils.isBlank(date)){
                end = FlashcatKit.getNowTime(null);
                start= FlashcatKit.getNowTime((long) (30 * 60 * 1000));
            }else {
                start = FlashcatKit.formatTime(date+" "+startHour);
                end = FlashcatKit.formatTime(date+" "+endHour);
            }
            Long contrastStart =null;
            Long contrastEnd =null;
            if(StringUtils.isNotBlank(contrastDate)){
                contrastStart = FlashcatKit.formatTime(contrastDate+" "+startHour);
                contrastEnd = FlashcatKit.formatTime(contrastDate+" "+endHour);
            }
            ObjectMapper mapper = new ObjectMapper();
            // 创建一个ArrayNode对象
            ArrayNode jsonArray = mapper.createArrayNode();
            JsonNode chainmakerAvgTps = FlashcatKit.chainmakerTps(chainId, job, start, end, step,datasoureId, authorization);
            if(chainmakerAvgTps!=null&&"success".equals(chainmakerAvgTps.get("status").asText())){
                jsonArray.add(chainmakerAvgTps.get("data").get("result"));
            }else {
                jsonArray.addArray();
            }
            JsonNode chainmakerAvgTps2 = FlashcatKit.chainmakerTps(chainId, job, contrastStart, contrastEnd, step,datasoureId, authorization);
            if(chainmakerAvgTps2!=null&&"success".equals(chainmakerAvgTps2.get("status").asText())){
                jsonArray.add(chainmakerAvgTps2.get("data").get("result"));
            }else {
                jsonArray.addArray();
            }
            return  jsonArray;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 待打包交易数
     * chainId 链ID
     * job  链节点
     *  date  日期
     * contrastDate 比对日期
     * startHour  开始时间（小时）
     * endHour   结束时间（小时）
     * step   时间颗粒度
     *  datasoureId 数据源id
     * authorization  认证字符串
     */
    public ArrayNode chainmakerTxCounter(String chainId, String job, String date, String contrastDate, String startHour, String endHour, String step,String datasoureId, String authorization){
        try{
            if(StringUtils.isBlank(startHour)){
                LocalTime oneHourAgoTime = LocalTime.now().minusHours(2);
                startHour = oneHourAgoTime.format(DateTimeFormatter.ofPattern("HH:mm:ss"));
            }
            if(StringUtils.isBlank(endHour)){
                endHour = LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss"));
            }
            Long start =null;
            Long end =null;
            if(StringUtils.isBlank(date)){
                end = FlashcatKit.getNowTime(null);
                start= FlashcatKit.getNowTime((long) (30 * 60 * 1000));
            }else {
                start = FlashcatKit.formatTime(date+" "+startHour);
                end = FlashcatKit.formatTime(date+" "+endHour);
            }
            Long contrastStart =null;
            Long contrastEnd =null;
            if(StringUtils.isNotBlank(contrastDate)){
                contrastStart = FlashcatKit.formatTime(contrastDate+" "+startHour);
                contrastEnd = FlashcatKit.formatTime(contrastDate+" "+endHour);
            }
            ObjectMapper mapper = new ObjectMapper();
            // 创建一个ArrayNode对象
            ArrayNode jsonArray = mapper.createArrayNode();
            JsonNode chainmaker = FlashcatKit.chainmakerTxCounter(chainId, job, start, end, step,datasoureId, authorization);
            if(chainmaker!=null&&"success".equals(chainmaker.get("status").asText())){
                jsonArray.add(chainmaker.get("data").get("result"));
            }else {
                jsonArray.addArray();
            }
            JsonNode chainmaker2 = FlashcatKit.chainmakerTxCounter(chainId, job, contrastStart, contrastEnd, step,datasoureId, authorization);
            if(chainmaker2!=null&&"success".equals(chainmaker2.get("status").asText())){
                jsonArray.add(chainmaker2.get("data").get("result"));
            }else {
                jsonArray.addArray();
            }
            return  jsonArray;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    /**
     *区块链交易类请求数
     * chainId 链ID
     * job  链节点
     *  date  日期
     * contrastDate 比对日期
     * startHour  开始时间（小时）
     * endHour   结束时间（小时）
     * step   时间颗粒度
     *  datasoureId 数据源id
     * authorization  认证字符串
     */
    public ArrayNode chainmakerInvokeRequest(String chainId, String job, String date, String contrastDate, String startHour, String endHour, String step,String datasoureId, String authorization){
        try{
            if(StringUtils.isBlank(startHour)){
                LocalTime oneHourAgoTime = LocalTime.now().minusHours(2);
                startHour = oneHourAgoTime.format(DateTimeFormatter.ofPattern("HH:mm:ss"));
            }
            if(StringUtils.isBlank(endHour)){
                endHour = LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss"));
            }
            Long start =null;
            Long end =null;
            if(StringUtils.isBlank(date)){
                end = FlashcatKit.getNowTime(null);
                start= FlashcatKit.getNowTime((long) (30 * 60 * 1000));
            }else {
                start = FlashcatKit.formatTime(date+" "+startHour);
                end = FlashcatKit.formatTime(date+" "+endHour);
            }
            Long contrastStart =null;
            Long contrastEnd =null;
            if(StringUtils.isNotBlank(contrastDate)){
                contrastStart = FlashcatKit.formatTime(contrastDate+" "+startHour);
                contrastEnd = FlashcatKit.formatTime(contrastDate+" "+endHour);
            }
            ObjectMapper mapper = new ObjectMapper();
            // 创建一个ArrayNode对象
            ArrayNode jsonArray = mapper.createArrayNode();
            JsonNode chainmaker = FlashcatKit.chainmakerInvokeRequest(chainId,job, start, end, step,datasoureId, authorization);
            if(chainmaker!=null&&"success".equals(chainmaker.get("status").asText())){
                jsonArray.add(chainmaker.get("data").get("result"));
            }else {
                jsonArray.addArray();
            }
            JsonNode chainmaker2 = FlashcatKit.chainmakerInvokeRequest(chainId,job, contrastStart, contrastEnd, step,datasoureId, authorization);
            if(chainmaker2!=null&&"success".equals(chainmaker2.get("status").asText())){
                jsonArray.add(chainmaker2.get("data").get("result"));
            }else {
                jsonArray.addArray();
            }
            return  jsonArray;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    /**
     **区块链查询类请求数
     * chainId 链ID
     * job  链节点
     *  date  日期
     * contrastDate 比对日期
     * startHour  开始时间（小时）
     * endHour   结束时间（小时）
     * step   时间颗粒度
     *  datasoureId 数据源id
     * authorization  认证字符串
     */
    public ArrayNode chainmakerQueryRequest(String chainId, String job,String date, String contrastDate, String startHour, String endHour, String step,String datasoureId, String authorization){
        try{
            if(StringUtils.isBlank(startHour)){
                LocalTime oneHourAgoTime = LocalTime.now().minusHours(2);
                startHour = oneHourAgoTime.format(DateTimeFormatter.ofPattern("HH:mm:ss"));
            }
            if(StringUtils.isBlank(endHour)){
                endHour = LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss"));
            }
            Long start =null;
            Long end =null;
            if(StringUtils.isBlank(date)){
                end = FlashcatKit.getNowTime(null);
                start= FlashcatKit.getNowTime((long) (30 * 60 * 1000));
            }else {
                start = FlashcatKit.formatTime(date+" "+startHour);
                end = FlashcatKit.formatTime(date+" "+endHour);
            }
            Long contrastStart =null;
            Long contrastEnd =null;
            if(StringUtils.isNotBlank(contrastDate)){
                contrastStart = FlashcatKit.formatTime(contrastDate+" "+startHour);
                contrastEnd = FlashcatKit.formatTime(contrastDate+" "+endHour);
            }
            ObjectMapper mapper = new ObjectMapper();
            // 创建一个ArrayNode对象
            ArrayNode jsonArray = mapper.createArrayNode();
            JsonNode chainmaker = FlashcatKit.chainmakerQueryRequest(chainId,job, start, end, step,datasoureId, authorization);
            if(chainmaker!=null&&"success".equals(chainmaker.get("status").asText())){
                jsonArray.add(chainmaker.get("data").get("result"));
            }else {
                jsonArray.addArray();
            }
            JsonNode chainmaker2 = FlashcatKit.chainmakerQueryRequest(chainId,job, contrastStart, contrastEnd, step, datasoureId,authorization);
            if(chainmaker2!=null&&"success".equals(chainmaker2.get("status").asText())){
                jsonArray.add(chainmaker2.get("data").get("result"));
            }else {
                jsonArray.addArray();
            }
            return  jsonArray;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }


    /**
     **区块链平均块大小
     * chainId 链ID
     * job  链节点
     *  date  日期
     * contrastDate 比对日期
     * startHour  开始时间（小时）
     * endHour   结束时间（小时）
     * step   时间颗粒度
     *  datasoureId 数据源id
     * authorization  认证字符串
     */
    public ArrayNode chainmakerAvgBlockSize(String chainId, String job,String date, String contrastDate, String startHour, String endHour, String step,String datasoureId, String authorization){
        try{
            if(StringUtils.isBlank(startHour)){
                LocalTime oneHourAgoTime = LocalTime.now().minusHours(2);
                startHour = oneHourAgoTime.format(DateTimeFormatter.ofPattern("HH:mm:ss"));
            }
            if(StringUtils.isBlank(endHour)){
                endHour = LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss"));
            }
            Long start =null;
            Long end =null;
            if(StringUtils.isBlank(date)){
                end = FlashcatKit.getNowTime(null);
                start= FlashcatKit.getNowTime((long) (30 * 60 * 1000));
            }else {
                start = FlashcatKit.formatTime(date+" "+startHour);
                end = FlashcatKit.formatTime(date+" "+endHour);
            }
            Long contrastStart =null;
            Long contrastEnd =null;
            if(StringUtils.isNotBlank(contrastDate)){
                contrastStart = FlashcatKit.formatTime(contrastDate+" "+startHour);
                contrastEnd = FlashcatKit.formatTime(contrastDate+" "+endHour);
            }
            ObjectMapper mapper = new ObjectMapper();
            // 创建一个ArrayNode对象
            ArrayNode jsonArray = mapper.createArrayNode();
            JsonNode chainmaker = FlashcatKit.chainmakerAvgBlockSize(chainId,job, start, end, step,datasoureId, authorization);
            if(chainmaker!=null&&"success".equals(chainmaker.get("status").asText())){
                jsonArray.add(chainmaker.get("data").get("result"));
            }else {
                jsonArray.addArray();
            }
            JsonNode chainmaker2 = FlashcatKit.chainmakerAvgBlockSize(chainId,job, contrastStart, contrastEnd, step, datasoureId,authorization);
            if(chainmaker2!=null&&"success".equals(chainmaker2.get("status").asText())){
                jsonArray.add(chainmaker2.get("data").get("result"));
            }else {
                jsonArray.addArray();
            }
            return  jsonArray;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    /**
     **区块链平均出块周期
     * chainId 链ID
     * job  链节点
     *  date  日期
     * contrastDate 比对日期
     * startHour  开始时间（小时）
     * endHour   结束时间（小时）
     * step   时间颗粒度
     *  datasoureId 数据源id
     * authorization  认证字符串
     */
    public ArrayNode chainmakerAvgBlockOutput(String chainId, String job,String date, String contrastDate, String startHour, String endHour, String step,String datasoureId, String authorization){
        try{
            if(StringUtils.isBlank(startHour)){
                LocalTime oneHourAgoTime = LocalTime.now().minusHours(2);
                startHour = oneHourAgoTime.format(DateTimeFormatter.ofPattern("HH:mm:ss"));
            }
            if(StringUtils.isBlank(endHour)){
                endHour = LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss"));
            }
            Long start =null;
            Long end =null;
            if(StringUtils.isBlank(date)){
                end = FlashcatKit.getNowTime(null);
                start= FlashcatKit.getNowTime((long) (30 * 60 * 1000));
            }else {
                start = FlashcatKit.formatTime(date+" "+startHour);
                end = FlashcatKit.formatTime(date+" "+endHour);
            }
            Long contrastStart =null;
            Long contrastEnd =null;
            if(StringUtils.isNotBlank(contrastDate)){
                contrastStart = FlashcatKit.formatTime(contrastDate+" "+startHour);
                contrastEnd = FlashcatKit.formatTime(contrastDate+" "+endHour);
            }
            ObjectMapper mapper = new ObjectMapper();
            // 创建一个ArrayNode对象
            ArrayNode jsonArray = mapper.createArrayNode();
            JsonNode chainmaker = FlashcatKit.chainmakerAvgBlockOutput(chainId,job, start, end, step,datasoureId, authorization);
            if(chainmaker!=null&&"success".equals(chainmaker.get("status").asText())){
                jsonArray.add(chainmaker.get("data").get("result"));
            }else {
                jsonArray.addArray();
            }
            JsonNode chainmaker2 = FlashcatKit.chainmakerAvgBlockOutput(chainId,job, contrastStart, contrastEnd, step, datasoureId,authorization);
            if(chainmaker2!=null&&"success".equals(chainmaker2.get("status").asText())){
                jsonArray.add(chainmaker2.get("data").get("result"));
            }else {
                jsonArray.addArray();
            }
            return  jsonArray;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    /**
     **区块链平均Tps
     * chainId 链ID
     * job  链节点
     *  date  日期
     * contrastDate 比对日期
     * startHour  开始时间（小时）
     * endHour   结束时间（小时）
     * step   时间颗粒度
     *  datasoureId 数据源id
     * authorization  认证字符串
     */
    public ArrayNode chainmakerAvgTps(String chainId, String job,String date, String contrastDate, String startHour, String endHour, String step,String datasoureId, String authorization){
        try{
            if(StringUtils.isBlank(startHour)){
                LocalTime oneHourAgoTime = LocalTime.now().minusHours(2);
                startHour = oneHourAgoTime.format(DateTimeFormatter.ofPattern("HH:mm:ss"));
            }
            if(StringUtils.isBlank(endHour)){
                endHour = LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss"));
            }
            Long start =null;
            Long end =null;
            if(StringUtils.isBlank(date)){
                end = FlashcatKit.getNowTime(null);
                start= FlashcatKit.getNowTime((long) (30 * 60 * 1000));
            }else {
                start = FlashcatKit.formatTime(date+" "+startHour);
                end = FlashcatKit.formatTime(date+" "+endHour);
            }
            Long contrastStart =null;
            Long contrastEnd =null;
            if(StringUtils.isNotBlank(contrastDate)){
                contrastStart = FlashcatKit.formatTime(contrastDate+" "+startHour);
                contrastEnd = FlashcatKit.formatTime(contrastDate+" "+endHour);
            }
            ObjectMapper mapper = new ObjectMapper();
            // 创建一个ArrayNode对象
            ArrayNode jsonArray = mapper.createArrayNode();
            JsonNode chainmaker = FlashcatKit.chainmakerAvgTps(chainId,job, start, end, step,datasoureId, authorization);
            if(chainmaker!=null&&"success".equals(chainmaker.get("status").asText())){
                jsonArray.add(chainmaker.get("data").get("result"));
            }else {
                jsonArray.addArray();
            }
            JsonNode chainmaker2 = FlashcatKit.chainmakerAvgTps(chainId,job, contrastStart, contrastEnd, step, datasoureId,authorization);
            if(chainmaker2!=null&&"success".equals(chainmaker2.get("status").asText())){
                jsonArray.add(chainmaker2.get("data").get("result"));
            }else {
                jsonArray.addArray();
            }
            return  jsonArray;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }


}
